#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <ctime>

using namespace std;

#define BEGINS(x) namespace x {
#define ENDS(x) } // end of namespace x

BEGINS(test1)
class Base {
public:
    virtual ~Base() {}
};

class A : public Base {};
class B : public Base {};
class C : public Base {};

int main() {
    srand(time(0));
    Base *p;
    switch(rand() % 4) {
        case 0: p = new A(); break;
        case 1: p = new B(); break;
        case 2: p = new C(); break;
        case 3: p = nullptr; break;
    }
    A a;
    if (p) ((void **)(p))[0] = ((void **)(&a))[0];
    if (dynamic_cast<A *>(p) != nullptr) { // p is A?
        cout << "p pointer A class Object" << endl;
    } else if (dynamic_cast<B *>(p) != nullptr) { // p is B?
        cout << "p pointer B class Object" << endl;
    } else if (dynamic_cast<C *>(p) != nullptr) { // p is C?
        cout << "p pointer c class Object" << endl;
    } else {
        cout << "p is nullptr" << endl;
    }
    return 0;
}
ENDS(test1)

int main() {
    for (int i = 0; i < 10; i++) {
        test1::main();
    }

    return 0;
}